<template>
    <div>
        <h2>展示游戏页面</h2>
    <table>
        <tr>
            <td>id</td>
            <td>name</td>
            <td>操作</td>
        </tr>
        <tr v-for="i in cates" :key="i.id">
            <td>{{i.id}}</td>
            <td>{{i.name}}</td>
            <td>
            <input type="button" value="修改" @click="updateg(i.id)">
            <input type="button" value="删除" @click="deleteg(i.name)">
            </td>
        </tr>    
    </table>
    </div>    
</template>

<script>
import axios from "axios"
import {deletegame} from "../axios_api/api.js"
export default {
    name:"showgame",
    data() {
        return {
            cates:"",
        }
    },
    mounted(){
        //向后台获取数据
        axios({
            url:'http://127.0.0.1:8000/app01/getgame/',
            method:'get'
        }).then(res=>{
            if(res.data.code==200){
                this.cates = res.data.data
            }
        })
    },
    methods:{
        updateg(id){
            this.$router.push({
                name:"updategame"
            })
        },
        deleteg(name){
            var data={"name":name}
            deletegame(data).then(res=>{
                console.log(res)
                window.location.reload();
            })
        }
    }
        
}
        
</script>

<style>

</style>
